import React, { Component } from 'react'
import { Form, Select, Input } from 'antd'
import PropTypes from 'prop-types'
/**
 * 添加分类的form组件
 */
const Item = Form.Item;
const Option = Select.Option;

export default class AddForm extends Component {
    static propTypes = {
        setForm: PropTypes.func.isRequired, // 用来传递form对象的函数
        categorys: PropTypes.array.isRequired, // 一级分类的数组
        parentId: PropTypes.string.isRequired, // 父分类的ID
    }

    onFinish = (values) => {
        console.log('Received values from form: ', values);
    };

    render() {
        const { categorys, parentId } = this.props
        return (
            <Form ref="form" initialValues={{
                'parentId': parentId,
              }}>
                <Item name="parentId" rules={[{ required: true, message: '请选择父级分类' }]}>
                    <Select size="large">
                        <Option value="0">一级分类</Option>
                        {
                            categorys.map(c => <Option key={c._id} value={c._id}>{c.name}</Option>)
                        }
                        {/* <Option value="1">电脑</Option>
                        <Option value="2">图书</Option> */}
                    </Select>
                </Item>
                <Item name="catName" rules={[{ required: true, message: '分类名称必须输入' }]}>
                    <Input placeholder="请输入分类名称"></Input>
                </Item>

            </Form>
        )
    }

}